package com.platform.api;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.platform.exception.ApplicationException;
import com.platform.exception.IErrorCode;
import com.platform.exception.SystemException;

public class Status {
    private Integer code = 0;
    private String msg = "OK";

    public Status() {

    }

    public Status(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Status(IErrorCode errorCode) {
        setErrorCode(errorCode);
    }

    public void setErrorCode(IErrorCode errorCode){
        this.code = errorCode.getCode();
        this.msg = errorCode.getMsg();
    }

    public void setException(ApplicationException exception){
        this.code = exception.getCode();
        this.msg = exception.getMsg();
    }

    public void setException(SystemException exception) {
        this.code = exception.getCode();
        this.msg = exception.getMsg();
    }

    @JsonIgnore
    public ApplicationException getException(){
        ApplicationException exception = new ApplicationException(this.code, this.msg);
        return exception;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public String toString() {
        return "{" +
                "code:" + code +
                ", msg:'" + msg + '\'' +
                '}';
    }
}
